/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model.npc.actiontalk;

import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1HardinQuest;
import com.lineage.server.model.L1PolyMorph;
import com.lineage.server.model.L1Teleport;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.npc.NpcExecutor;
import com.lineage.server.packetserver.S_NPCTalkReturn;

/**
 * Class <code>Id0</code> 尤吉:象牙塔秘密研究室(3.5C哈丁副本).
 * 
 * @author jrwz
 * @version 2012-7-13下午10:19:37
 * @see com.lineage.server.model.npc.actiontalk
 * @since JDK1.7
 */
public final class Id0 implements NpcExecutor {
    /**
     * 序列版本UID.
     */
    private static final long serialVersionUID = 1L;

    /**
     * 取得实例(当第一次实例为空时才新建一个).
     * 
     * @return 实例
     */
    public static NpcExecutor get() {
        return new Id0();
    }

    /** 尤吉:象牙塔秘密研究室(3.5C哈丁副本). */
    private Id0() {
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.lineage.server.model.npc.NpcExecutor#attack(com.lineage.server.model.Instance.L1PcInstance, com.lineage.server.model.Instance.L1NpcInstance)
     */
    @Override
    public void attack(final L1PcInstance pc, final L1NpcInstance npc) {
        // TODO Auto-generated method stub

    }

    /*
     * (non-Javadoc)
     * 
     * @see com.lineage.server.model.npc.NpcExecutor#death(com.lineage.server.model.L1Character, com.lineage.server.model.Instance.L1NpcInstance)
     */
    @Override
    public L1PcInstance death(final L1Character lastAttacker,
            final L1NpcInstance npc) {
        // TODO Auto-generated method stub
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.lineage.server.model.npc.NpcExecutor#npcTalkAction(com.lineage.server.model.Instance.L1PcInstance, com.lineage.server.model.Instance.L1NpcInstance, java.lang.String, int)
     */
    @Override
    public void npcTalkAction(final L1PcInstance pc, final L1NpcInstance npc,
            final String s, final int objid) {
        String htmlid = null;
        if (s.equalsIgnoreCase("enter")) { // 移动到过去
            int members = 1;
            for (final L1PcInstance player : pc.getKnownPlayers()) {
                if (pc.getParty().isMember(player)) {
                    members++;
                }
            }
            if ((pc.getParty().getNumOfMembers() == members)
                    && (pc.getParty().getNumOfMembers() >= 2)) { // 画面内
                if (L1HardinQuest.getInstance().getNumOfActiveMaps() < 50) {
                    final int instanceMap = L1HardinQuest.getInstance()
                            .setActiveMaps(9000);

                    for (final L1PcInstance ptmember : pc.getParty()
                            .getMembers()) {
                        L1PolyMorph.undoPoly(ptmember); // 解除变身
                        L1Teleport.teleport(ptmember, 32726, 32724,
                                (instanceMap), 6, true); // 全队传送
                        L1HardinQuest.getInstance().getActiveMaps(instanceMap)
                                .setLeader(pc); // 设置队长
                        L1HardinQuest.getInstance().getActiveMaps(instanceMap)
                                .start(); // 启动任务
                    }
                    htmlid = "";
                }
            } else {
                htmlid = "id0_1";
            }
        }
        if (htmlid != null) {
            pc.sendPackets(new S_NPCTalkReturn(npc.getId(), htmlid));
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.lineage.server.model.npc.NpcExecutor#npcTalkReturn(com.lineage.server.model.Instance.L1PcInstance, com.lineage.server.model.Instance.L1NpcInstance)
     */
    @Override
    public void npcTalkReturn(final L1PcInstance pc, final L1NpcInstance npc) {
        String htmlid = null;
        if (pc.isInParty()) {
            if (pc.getParty().isLeader(pc)) {
                htmlid = "id0";
            } else {
                htmlid = "id0_2";
            }
        }
        if (htmlid != null) {
            pc.sendPackets(new S_NPCTalkReturn(npc.getId(), htmlid));
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.lineage.server.model.npc.NpcExecutor#spawn(com.lineage.server.model.Instance.L1NpcInstance)
     */
    @Override
    public void spawn(final L1NpcInstance npc) {
        // TODO Auto-generated method stub

    }

    /*
     * (non-Javadoc)
     * 
     * @see com.lineage.server.model.npc.NpcExecutor#type()
     */
    @Override
    public int type() {
        // TODO Auto-generated method stub
        return 3;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.lineage.server.model.npc.NpcExecutor#work(com.lineage.server.model.Instance.L1NpcInstance)
     */
    @Override
    public void work(final L1NpcInstance npc) {
        // TODO Auto-generated method stub

    }

    /*
     * (non-Javadoc)
     * 
     * @see com.lineage.server.model.npc.NpcExecutor#workTime()
     */
    @Override
    public int workTime() {
        // TODO Auto-generated method stub
        return 0;
    }
}
